﻿Public Class frmConfigurarModulos

#Region "Variáveis"

    Private objModulos As New Controle.ctrModulos
    Private datModulos As New DataTable

#End Region

#Region "Eventos"

    Private Sub frmConfigurarModulos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try

            Me.preencherGrid()
            MyBase.visibilidadeBotoes(False, False, True, True)

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub frmConfigurarModulos_alteraModo(ByVal eModoAtual As FronteiraPadrao.frmPadrao.eModo) Handles Me.alteraModo
        MyBase.cmdCancelar.Enabled = (Me.acessoAlterar OrElse Me.acessoInserir)
    End Sub

    Private Sub frmConfigurarModulos_alterar(ByRef bCancel As Boolean) Handles Me.alterar
        Me.fraGeral.Enabled = True
    End Sub

    Private Sub frmConfigurarModulos_cancelar(ByRef bCancel As Boolean) Handles Me.cancelar
        Me.preencherGrid()
        Me.fraGeral.Enabled = False
    End Sub

    Private Sub frmConfigurarModulos_gravar(ByRef bCancel As Boolean) Handles Me.gravar

        Try

            Me.objModulos.gravarModulos(Me.datModulos)
            Me.preencherGrid()
            Me.fraGeral.Enabled = False

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub dgvModulo_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvModulo.CellClick

        Try

            If e.RowIndex >= 0 Then

                If Me.dgvModulo.CurrentCell.OwningColumn.Name = "buscarExe" Then

                    Dim openDlg As OpenFileDialog = New OpenFileDialog()
                    openDlg.Title = "Selecionar Executável"
                    openDlg.Filter = "Executável (*.exe)|*.exe"

                    If (openDlg.ShowDialog() = Windows.Forms.DialogResult.OK) Then

                        Me.dgvModulo.CurrentRow.Cells("caminhoExe").Value = openDlg.FileName

                    End If

                End If

                If Me.dgvModulo.CurrentCell.OwningColumn.Name = "buscarAtu" Then

                    Dim folder As FolderBrowserDialog = New FolderBrowserDialog

                    folder.Description = "Selecionar Pasta Atualização"

                    If (folder.ShowDialog() = Windows.Forms.DialogResult.OK) Then

                        Me.dgvModulo.CurrentRow.Cells("caminhoAtu").Value = folder.SelectedPath

                    End If

                End If

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

#End Region

#Region "Métodos"

    Private Sub preencherGrid()

        Me.datModulos = Me.objModulos.selecionarModulos
        Me.dgvModulo.DataSource = Me.datModulos

        For Each drDados As DataGridViewRow In Me.dgvModulo.Rows
            drDados.Cells("buscarExe").Value = My.Resources.Lupa
            drDados.Cells("buscarAtu").Value = My.Resources.Lupa
        Next

    End Sub

#End Region


    Private Sub dgvModulo_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvModulo.CellContentClick

    End Sub

    Private Sub dgvModulo_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles dgvModulo.RowsAdded
        Try
            dgvModulo.Rows(e.RowIndex).Cells("buscarExe").Value = My.Resources.Lupa
            dgvModulo.Rows(e.RowIndex).Cells("buscarAtu").Value = My.Resources.Lupa
        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class